#include "Multimi.h"
void Multime::citire()
{
    int a,i=0;
    bool apartine;
    cout<<"Introduceti nr. de elemente:"; cin>>this->k;
    while (i<this->k)
    {
        cout<<"Introduceti elementul:";cin>>a;
        apartine=true;
        for(int j=0;j<i;j++) if(a==this->m[j]) { apartine=false; cout<<"Elementul exista in multime:"<<endl; }
        if(apartine==true) {this->m[i]=a; i++;}

    }
}
void Multime::afisare()
{
    cout<<"{";
    for(int i=0;i<this->k-1;i++) cout<<this->m[i]<<", ";
    cout<<this->m[this->k-1]<<"}"<<endl;
}
bool Multime::apartine(int x)
{
    bool t=false;
    for(int i=0;i<this->k;i++) if(this->m[i]==x) t=true;
    return t;
}
void Multime::adaugare(int x)
{
    if (this->apartine(x)==false) {
    this->m[this->k]=x;
    this->k=this->k++;
    }
}
void Multime::setNrElemente(int k)
{
    this->k=k;
}
int Multime::nrElemente()
{
    return this->k;
}
void Multime::setElement(int x, int k)
{
    if(this->apartine(x)==false) this->m[k]=x;
}
int Multime::getElement(int i)
{
    return this->m[i];
}
Multime Multime::reuniune(Multime k)
{
    Multime re;
    int a=this->nrElemente(),b=k.nrElemente(),nr=a;
    for(int i=0;i<a;i++) {re.setNrElemente(i); re.setElement(this->m[i], i);}
    for(int j=0;j<b;j++) if(re.apartine(k.getElement(j))==false){ re.setElement(k.getElement(j),a-1); a++; re.setNrElemente(a-1);}
return re;
}
Multime Multime::intersectie(Multime k)
{
    Multime in;
    int a=this->nrElemente(),b=k.nrElemente(),nr=0;
    for(int i=0;i<a;i++) {
    for(int j=0;j<b;j++) if(this->getElement(i)==k.getElement(j)) {in.setElement(this->getElement(i),nr); nr++;}
    in.setNrElemente(nr);
    }
return in;
}
Multime Multime::diferenta(Multime x)
{
    bool t;
    Multime dif;
    int a=this->nrElemente(),b=x.nrElemente(),nr=0;
    for(int i=0;i<a;i++) {
    t=true;
    for(int j=0;j<b;j++) if(this->getElement(i)==x.getElement(j)) t=false;
    if(t){
    dif.setElement(this->getElement(i),nr); nr++;
    dif.setNrElemente(nr);}
    }
    return dif;
}
bool Multime::incluziune(Multime x)
{
    bool t1,t2;
    int a=this->nrElemente(),b=x.nrElemente(),nr=0;
    t1=true;
    for(int i=0;i<a;i++) {
    t2=false;
    for(int j=0;j<b;j++) if(this->getElement(i)==x.getElement(j)) t2=true;
    if (t2==false) t1=false;
    }
    return t1;
}
